Vue.component('Add', {
	template: `
		<el-dialog title="添加" width="1000px" class="icon-dialog" :visible.sync="show" @open="open" :before-close="closeForm" append-to-body>
			<el-form :size="size" ref="form" :model="form" :rules="rules" :label-width=" ismobile()?'90px':'16%'">
				<el-row >
					<el-col :span="24">
						<el-form-item label="学生档案ID" prop="children_id">
							<el-input  v-model="form.children_id" autoComplete="off" clearable  placeholder="请输入学生档案ID"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="需求标题" prop="require_title">
							<el-input  v-model="form.require_title" autoComplete="off" clearable  placeholder="请输入需求标题"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="学生姓名" prop="children_name">
							<el-input  v-model="form.children_name" autoComplete="off" clearable  placeholder="请输入学生姓名"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="学生年级" prop="require_grade">
							<el-select   style="width:100%" v-model="form.require_grade" filterable clearable placeholder="请选择学生年级">
								<el-option v-for="(item,i) in require_grades" :key="i" :label="item.key" :value="item.val"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="辅导学科" prop="require_subject">
							<el-select multiple style="width:100%" v-model="form.require_subject" filterable clearable placeholder="请选择辅导学科">
								<el-option v-for="(item,i) in require_subjects" :key="i" :label="item.key" :value="item.val.toString()"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="当前学习水平" prop="current_learning">
							<el-input  type="textarea" autoComplete="off" v-model="form.current_learning"  :autosize="{ minRows: 2, maxRows: 4}" clearable placeholder="请输入当前学习水平"/>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="期望达到目标" prop="expect_learning">
							<el-input  type="textarea" autoComplete="off" v-model="form.expect_learning"  :autosize="{ minRows: 2, maxRows: 4}" clearable placeholder="请输入期望达到目标"/>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="期望授课开始时间" prop="expect_start_time">
							<el-input  v-model="form.expect_start_time" autoComplete="off" clearable  placeholder="请输入期望授课开始时间"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="期望授课结束时间" prop="expect_end_time">
							<el-input  v-model="form.expect_end_time" autoComplete="off" clearable  placeholder="请输入期望授课结束时间"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="期望授课频次" prop="expect_frequency">
							<el-select style="width:100%" v-model="form.expect_frequency" filterable clearable placeholder="请选择期望授课频次">
								<el-option key="0" label="每周1次" :value="1"></el-option>
								<el-option key="1" label="每周2次" :value="2"></el-option>
								<el-option key="2" label="每周3次" :value="3"></el-option>
								<el-option key="3" label="每天" :value="4"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="授课时长" prop="teach_hour">
							<el-input  v-model="form.teach_hour" autoComplete="off" clearable  placeholder="请输入授课时长"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="授课地点" prop="teach_address">
							<el-input  v-model="form.teach_address" autoComplete="off" clearable  placeholder="请输入授课地点"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="授课地点详情" prop="teach_address_detail">
							<el-input  v-model="form.teach_address_detail" autoComplete="off" clearable  placeholder="请输入授课地点详情"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="授课地点经度" prop="teach_address_lng">
							<el-input  v-model="form.teach_address_lng" autoComplete="off" clearable  placeholder="请输入授课地点经度"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="授课地点维度" prop="teach_address_lat">
							<el-input  v-model="form.teach_address_lat" autoComplete="off" clearable  placeholder="请输入授课地点维度"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="老师性别要求" prop="require_teacher_sex">
							<el-select style="width:100%" v-model="form.require_teacher_sex" filterable clearable placeholder="请选择老师性别要求">
								<el-option key="0" label="无要求" :value="0"></el-option>
								<el-option key="1" label="男" :value="1"></el-option>
								<el-option key="2" label="女" :value="2"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="教学经验要求" prop="require_teacher_year">
							<el-select style="width:100%" v-model="form.require_teacher_year" filterable clearable placeholder="请选择教学经验要求">
								<el-option key="0" label="无要求" :value="0"></el-option>
								<el-option key="1" label="1年以上" :value="1"></el-option>
								<el-option key="2" label="3年以上" :value="2"></el-option>
								<el-option key="3" label="5年以上" :value="3"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="年龄偏好最小" prop="require_teacher_year_min">
							<el-input  v-model="form.require_teacher_year_min" autoComplete="off" clearable  placeholder="请输入年龄偏好最小"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="年龄偏好最大" prop="require_teacher_year_max">
							<el-input  v-model="form.require_teacher_year_max" autoComplete="off" clearable  placeholder="请输入年龄偏好最大"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="其他要求" prop="require_other">
							<el-input  type="textarea" autoComplete="off" v-model="form.require_other"  :autosize="{ minRows: 2, maxRows: 4}" clearable placeholder="请输入其他要求"/>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="课时费" prop="class_fee">
							<el-input-number controls-position="right" style="width:200px;" autoComplete="off" v-model="form.class_fee" clearable :min="0" placeholder="请输入课时费"/>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="预估课时" prop="estimated_hour">
							<el-input  v-model="form.estimated_hour" autoComplete="off" clearable  placeholder="请输入预估课时"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="联系人" prop="link_name">
							<el-input  v-model="form.link_name" autoComplete="off" clearable  placeholder="请输入联系人"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="联系人手机号" prop="link_mobile">
							<el-input  v-model="form.link_mobile" autoComplete="off" clearable  placeholder="请输入联系人手机号"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="需求状态" prop="require_status">
							<el-select style="width:100%" v-model="form.require_status" filterable clearable placeholder="请选择需求状态">
								<el-option key="0" label="草稿" :value="0"></el-option>
								<el-option key="1" label="已发布" :value="1"></el-option>
								<el-option key="2" label="招募中" :value="2"></el-option>
								<el-option key="3" label="已关闭" :value="4"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="审核状态" prop="cert_status">
							<el-select style="width:100%" v-model="form.cert_status" filterable clearable placeholder="请选择审核状态">
								<el-option key="0" label="待审核" :value="0"></el-option>
								<el-option key="1" label="审核成功" :value="1"></el-option>
								<el-option key="2" label="审核失败" :value="2"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="发布人ID" prop="parent_id">
							<el-input  v-model="form.parent_id" autoComplete="off" clearable  placeholder="请输入发布人ID"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button :size="size" :loading="loading" type="primary" @click="submit" >
					<span v-if="!loading">确 定</span>
					<span v-else>提 交 中...</span>
				</el-button>
				<el-button :size="size" @click="closeForm">取 消</el-button>
			</div>
		</el-dialog>
	`
	,
	components:{
	},
	props: {
		show: {
			type: Boolean,
			default: false
		},
		size: {
			type: String,
			default: 'small'
		},
	},
	data(){
		return {
			form: {
				children_id:'',
				require_title:'',
				children_name:'',
				require_grade:'',
				require_subject:[],
				current_learning:'',
				expect_learning:'',
				expect_start_time:'',
				expect_end_time:'',
				expect_frequency:1,
				teach_hour:'',
				teach_address:'',
				teach_address_detail:'',
				teach_address_lng:'',
				teach_address_lat:'',
				require_teacher_sex:0,
				require_teacher_year:0,
				require_teacher_year_min:'',
				require_teacher_year_max:'',
				require_other:'',
				estimated_hour:'',
				link_name:'',
				link_mobile:'',
				require_status:0,
				cert_status:0,
				cert_time:'',
				parent_id:'',
				create_time:'',
				update_time:'',
			},
			require_grades:[],
			require_subjects:[],
			loading:false,
			rules: {
				link_mobile:[
					{pattern:/^1[3456789]\d{9}$/, message: '联系人手机号格式错误'}
				],
			}
		}
	},
	watch:{
		show(val){
			if(val){
				axios.post(base_url + '/Parents.Requirement/getFieldList').then(res => {
					if(res.data.status == 200){
						this.require_grades = res.data.data.require_grades
						this.require_subjects = res.data.data.require_subjects
					}
				})
			}
		}
	},
	methods: {
		open(){
		},
		submit(){
			this.$refs['form'].validate(valid => {
				if(valid) {
					this.loading = true
					axios.post(base_url + '/Parents.Requirement/add',this.form).then(res => {
						if(res.data.status == 200){
							this.$message({message: res.data.msg, type: 'success'})
							this.$emit('refesh_list')
							this.closeForm()
						}else{
							this.loading = false
							this.$message.error(res.data.msg)
						}
					}).catch(()=>{
						this.loading = false
					})
				}
			})
		},
		closeForm(){
			this.$emit('update:show', false)
			this.loading = false
			if (this.$refs['form']!==undefined) {
				this.$refs['form'].resetFields()
			}
		},
	}
})
